package com.action.mvc.sm.rabbit;

import com.alibaba.fastjson.JSON;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 消费者
 */
@Component
public class MessageExecuteProducer {

    private final Logger logger = LogManager.getLogger(MessageExecuteProducer.class);

    @Autowired
    RabbitTemplate rabbitTemplate;

    /**
     * 发送消息
     */
    public void sendMessageExecuteMessage(Object message) {
        try {
            rabbitTemplate.convertAndSend(MessageExecuteConfig.MESSAGE_EXCHANGE, MessageExecuteConfig.MESSAGE_ROUTER_KEY, JSON.toJSONString(message));
        } catch (Exception e) {
            logger.error("RabbitMQ发送消息异常：" + e.getMessage());
        }
    }

}
